<template>
	<view class="body">
		<view class="content">
			<u-button @click="nav('/pages/workorder/category')" class="button-item" type="default">提交工单</u-button>
			<u-button @click="nav('/pages/my-workorder/my-workorder')" class="button-item" type="success">我的工单</u-button>
			<u-button v-if="engineer" @click="nav('/pages/workorder-manage/workorder-manage')" class="button-item" type="primary">工单管理</u-button>
			<u-button @click="clearStorage" class="button-item" type="error">清理缓存</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				engineer: false
			}
		},
		onLoad(query) {
			if (query.order_id) {
				uni.navigateTo({
					url: '/pages/workorder-info/workorder-info?id=' + query.order_id
				})
				return false;
			}
			this.load()
		},
		methods: {
			load: function () {
				this.$u.api.getIndex().then(res => {
					this.engineer = res.data.engineer
				})
			},
			nav: function (url) {
				uni.navigateTo({
					url: url
				})
			},
			clearStorage: function () {
				uni.showModal({
					title: '温馨提示',
					content: '清理缓存后需要重新登录，确认清理缓存吗？',
					success: res => {
						if (res.confirm) {
							uni.clearStorageSync()
							this.load()
						}
					}
				})
			}
		}
	}
</script>

<style>
.body {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100vh;
}
.content {
	width: 60vw;
	box-sizing: border-box;
}
.button-item {
	display: block;
	margin-bottom: 40rpx;
}
</style>
